package com.gxwuz.maven.action;

import java.util.Map;

import org.apache.struts2.interceptor.RequestAware;

import com.gxwuz.maven.entity.Business;
import com.gxwuz.maven.service.BusinessServiceImp;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;

public class BusinessAction extends ActionSupport implements Preparable,ModelDriven<Business>,RequestAware {

	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private BusinessServiceImp businessServiceImp;
	private Business business;
	private Integer id;
	private Map<String, Object> requestMap;

	
	

	public void setId(Integer id) {
		this.id = id;
	}

	public void setBusinessServiceImp(BusinessServiceImp businessServiceImp) {
		this.businessServiceImp = businessServiceImp;
	}

	public void setBusiness(Business business) {
		this.business = business;
	}

	
	public String list() {
		requestMap.put("businesses", businessServiceImp.findAll());
		return "list";
	}
	
	public String delete(Integer id) {
		businessServiceImp.delete(id);
		return "delete";
	}
	
	public String save() {
		businessServiceImp.save(business);
		return "save";
	}
	
	public void prepareSave() {
		if(business == null) {
			business = new Business();
		}
	}
	
	
	public void prepare() throws Exception {}

	public void setRequest(Map<String, Object> request) {
		this.requestMap = request;
	}

	public Business getModel() {
		return business;
	}
	
}
